def is_prime(n):
    if n <= 1:
        return False
    if n <= 3:
        return True
    if n % 2 == 0 or n % 3 == 0:
        return False
    i = 5
    while i * i <= n:
        if n % i == 0 or n % (i + 2) == 0:
            return False
        i += 6
    return True

def next_prime(num):
    while True:
        if is_prime(num):
            return num
        num += 1

def prev_prime(num):
    while True:
        if is_prime(num):
            return num
        num -= 1

num_words = input().split()
num_dict = {"zero": 0, "one": 1, "two": 2, "three": 3, "four": 4, "five": 5, "six": 6, "seven": 7, "eight": 8, "nine": 9}

try:
    num = int (str(num_dict[num_words[0]]) + str(num_dict[num_words[1]]) + str(num_dict[num_words[2]]))
    if is_prime(num):
        print(num)
    else:
        smaller_prime = prev_prime(num-1)
        larger_prime = next_prime(num+1)
        if abs(num-smaller_prime) <= abs(num-larger_prime):
            print(smaller_prime)
        else:
            print(larger_prime)
except:
    print("Wrong input")

